<%@ page import="java.net.*,java.sql.*,database.*"%>
<%
try{		
                String un = request.getParameter("UserName");
		String ps = request.getParameter("PassWord");
			DBCon db = new DBCon(out);
			ResultSet res = db.login(un, ps);
                        if (db.whoAmI == 4) {
                            session.setAttribute("admin", "admin");
                            response.sendRedirect("../admin/index.jsp");
                        }
			else if (res!= null && res.next()) {
				String id = res.getString("id");
				/*
				if (request.getParameter("cookie") == "true")
				{
				Cookie cookie = new Cookie("un", un);
				Cookie cookie2 = new Cookie("PassWord", ps);
				Cookie cookie3 = new Cookie("id", Integer.toString(id));
				//two weeks
				cookie.setMaxAge(60 * 60 * 24 * 14);
				response.addCookie(cookie);
				}
				 */
				session.setAttribute("un", un);
				session.setAttribute("PassWord", ps);
                                
				if (db.whoAmI == 1) {
					session.setAttribute("id", id);
					response.sendRedirect("../Student/index.jsp");
				} else if (db.whoAmI == 2) {
					session.setAttribute("ProfID", id);					
                    response.sendRedirect("../Proff/index.jsp");
				} else if (db.whoAmI == 3) {
					session.setAttribute("ProfID", id);
					session.setAttribute("comm", "com");
                                        
					response.sendRedirect("../Proff/index.jsp");
				}else {
					response.sendRedirect("../index.jsp?wrong");
				}
			} else {
				if (db.whoAmI==-1)
					{
					response.sendRedirect("../index.jsp?pending");
				}else if(db.whoAmI==-3)
					{
					response.sendRedirect("../index.jsp?stop");
                               }
				else
				response.sendRedirect("../index.jsp?wrong");
			}
                        }
catch(Exception e)
{
    response.sendRedirect("../connectionFailed.jsp?"+e);
}

%>